<?php
$id = $_GET['id'];
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',12);
$db = new Database();
//select record from tbredeem
$redeem = explode(",", $id);

$pdf->Ln();
//for the logo
$getSettings = $db->query("SELECT * FROM tbsettings");
foreach($getSettings as $value){
    $Invoice = $value['UpdateInvoice'];
    $Product = $value['UpdateProduct'];
    $logo = $value['logo'];
    $SystemName = $value['SystemName'];
    $footer = $value['footer'];
}
$pdf->Image("images/logo/logo.png",10,10,70);
$pdf->Ln();
$pdf->Cell(10,25,"");
$pdf->Ln();
// Colors, line width and bold font
$pdf->SetFillColor(255,0,150);
$pdf->SetTextColor(255);
$pdf->SetDrawColor(255,0,150);
$pdf->SetLineWidth(.3);
$pdf->SetFont('','B');
//header of the table
$cttr = 0;
    $pdf->Cell(120,7,"Description",1,0,'C',true);
    $pdf->Cell(30,7,"Item Code",1,0,'C',true);
    $pdf->Cell(20,7,"Quantity",1,0,'C',true);
    $pdf->Cell(25,7,"Date",1,0,'C',true); 
    // Color and font restoration
    $pdf->SetFillColor(224,235,255);
    $pdf->SetTextColor(0);
    $pdf->SetFont('');
    // Data
    $pdf->Ln();
    $fill = false;
for($b=0;$b<count($redeem);$b++){
    $as = explode("_", $redeem[$b]);
    $getSummary = $db->query("SELECT * FROM tbredeem WHERE id='$as[0]'","array");
    
    foreach($getSummary as $summary){
            $quan = explode(",",$summary['quantity']);
            $prodID = explode(",", $summary['product_id']);
            for($a=0;$a<count($quan);$a++){
                $getProd = $db->query("SELECT * FROM tbproduct WHERE id='$prodID[$a]'","row");
                
                if($prodID[$a]==$as[1]){
                    $pdf->Cell(120,6,$getProd['product_name'],'LR',0,'L',$fill);
                    $pdf->Cell(30,6,$getProd['itemCode'],'LR',0,'C',$fill);
                    $pdf->Cell(20,6,$quan[$a],'LR',0,'R',$fill);
                    $pdf->Cell(25,6,$summary['date'],'LR',0,'R',$fill);
                    $pdf->Ln();
                    $fill = !$fill;
                }
            }
    }
}
// Closing line
    $pdf->Cell(195,0,'','T');
$pdf->Ln(); // next line
$pdf->Output(); //outputing the pdf to the browser
?>